<?php
/** @noinspection PhpUnused */

namespace app\admin\controller\shop\goods;

use app\admin\controller\shop\Base;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;

/**
 * 商品参数模板管理
 */
class ParamsTemplate extends Base
{
    /**
     * ParamsTemplate模型对象
     * @var object
     * @phpstan-var \app\admin\model\shop\goods\ParamsTemplate
     */
    protected object $model;

    protected array|string $preExcludeFields = ['id', 'create_time', 'update_time'];

    protected string|array $quickSearchField = ['name'];

    public function initialize(): void
    {
        parent::initialize();
        $this->model = new \app\admin\model\shop\goods\ParamsTemplate;
    }

    protected array $noNeedPermission = ['template'];

    /**
     * 若需重写查看、编辑、删除等方法，请复制 @see \app\admin\library\traits\Backend 中对应的方法至此进行重写
     */

    /**
     * 模板
     * @return void
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function template(): void
    {
        $list = $this->model->where(['status' => 1])->field(['id', 'name', 'value'])->select()->toArray();

        $this->success('', [
            'list' => $list
        ]);
    }
}